#pragma once

#include "RBTree.h"

namespace Aron
{
	template<class K, class V>
	class map
	{
		struct MapKeyOfT
		{
			const K& operator()(const pair<K, V>& kv)
			{
				return kv.first;
			}
		};
		typedef RBTree<K, std::pair<const K, V>, MapKeyOfT> RBTree;
	public:
		typedef typename RBTree::iterator iterator;
		typedef typename RBTree::const_iterator const_iterator;
		typedef typename RBTree::reverse_iterator reverse_iterator;
		typedef typename RBTree::const_reverse_iterator const_reverse_iterator;

		iterator begin()
		{
			return _map.begin();
		}

		iterator end()
		{
			return _map.end();
		}

		const_iterator begin() const
		{
			return _map.begin();
		}

		const_iterator end() const
		{
			return _map.end();
		}

		reverse_iterator rbegin()
		{
			return _map.rbegin();
		}

		reverse_iterator rend()
		{
			return _map.rend();
		}

		const_reverse_iterator rbegin() const
		{
			return _map.rbegin();
		}

		const_reverse_iterator rend() const
		{
			return _map.rend();
		}

		bool Empty() const
		{
			return _map.Empty();
		}

		size_t Size() const
		{
			return _map.Size();
		}

		size_t Count(const K& key) const
		{
			return _map.Count(key);
		}

		std::pair<iterator, bool> insert(const pair<K, V>& kv)
		{
			return _map.Insert(kv);
		}

		iterator find(const K& key)
		{
			return _map.Find(key);
		}

		V& operator[](const K& key)
		{
			auto ret = _map.Insert(std::make_pair(key, V()));

			auto it = ret.first;

			return it->second;
		}

	private:
		RBTree _map;
	};

	//void test_map1()
	//{
	//	map<int, int> m;
	//	int a[] = { 4, 2, 6, 1, 3, 5, 15, 7, 16, 14 };
	//	for (auto e : a)
	//	{
	//		m.insert(make_pair(e, e));
	//	}

	//	map<int, int>::iterator it = m.begin();
	//	while (it != m.end())
	//	{
	//		//it->first += 100;
	//		it->second += 100;

	//		cout << it->first << ":" << it->second << endl;
	//		++it;
	//	}
	//	cout << endl;
	//}


}
